package com.ruiboyun.liveapp.base;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioGroup;


import com.ruiboyun.liveapp.util.tool.SnackbarUtils;

import java.util.Map;

import butterknife.ButterKnife;

/**
 * com.dafenci.android.teach.base
 * 公司:浙江答分奇网络科技有限公司
 * created by 吴世芊 on 2016/10/10 11:47.
 * updated by
 * 邮箱:apple9302@126.com
 * 此类功能:
 */

public abstract class BaseFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener
        , RadioGroup.OnCheckedChangeListener {
    public View mView;
    public Handler handler = new Handler();

    public int getWidth() {
        return getActivity().getResources().getDisplayMetrics().widthPixels;
    }

    public int getHeight() {
        return getActivity().getResources().getDisplayMetrics().heightPixels;
    }



    @Override
    public void onClick(View view) {

    }

    public void showSnackBar(View view, String msg) {
        SnackbarUtils.showSnackBar(view, msg);
    }

    public void showBottomSnackBar(View view, String msg) {

        SnackbarUtils.showBottomSnackBar(view, msg);
    }

    public void launcher(Class cls) {
        Intent intent = new Intent(getActivity(), cls);
        startActivity(intent);
    }

    public void launcher(Class cls, Map.Entry<String, String>... parms) {
        Intent intent = new Intent(getActivity(), cls);
        for (int i = 0; i < parms.length; i++) {
            intent.putExtra(parms[i].getKey(), parms[i].getValue());
        }
        startActivity(intent);

    }

    public void stopRefresh(final SwipeRefreshLayout refreshLayout){
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (refreshLayout!=null){
                    refreshLayout.setRefreshing(false);
                }
            }
        },1500);
    }
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

    }

    public abstract int getLayout();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayout(), null);
        mView = view;
        ButterKnife.bind(this, view);
        afterBindView();
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    public abstract void afterBindView();

}